all files / selectField/ selectField.vue

26.67% Statements 8/30
22.22% Branches 4/18
12.5% Functions 1/8
13.64% Lines 3/22
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120                          1× 1×                                                                                                                                                                                                                  
//
//
//
//
//
//
//
//
//
//
//
//
 
import textField from '../textField'
import dropDownMenu from '../dropDownMenu'
export default {
  name: 'mu-select-field',
  props: {
    label: {
      type: String
    },
    labelFloat: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    hintText: {
      type: String
    },
    helpText: {
      type: String
    },
    errorText: {
      type: String
    },
    errorColor: {
      type: String
    },
    icon: {
      type: String
    },
    maxHeight: {
      type: Number
    },
    autoWidth: {
      type: Boolean,
      default: false
    },
    fullWidth: {
      type: Boolean,
      default: false
    },
    underlineShow: {
      type: Boolean,
      default: true
    },
    value: {},
    multiple: {
      type: Boolean,
      default: false
    },
    scroller: {
      type: [window.HTMLDocument, window.Element, window.Window]
    }
  },
  data () {
    let defaultVal = this.value
    if (!defaultVal) defaultVal = ''
    if (this.multiple && !(defaultVal instanceof Array)) {
      defaultVal = []
    }
    return {
      anchorEl: null,
      inputValue: defaultVal
    }
  },
  mounted () {
    this.anchorEl = this.$children[0].$refs.input
  },
  methods: {
    handlehange (val) {
      if (val === this.inputValue) return
      if (this.multiple) {
        const index = this.inputValue.indexOf(val)
        if (index === -1) {
          this.inputValue.push(val)
        } else {
          this.inputValue.splice(index, 1)
        }
      } else {
        this.inputValue = val
      }
      this.$emit('change', this.inputValue)
    },
    handleOpen () {
      this.$refs.textField.handleFocus()
    },
    handleClose () {
      this.$refs.textField.handleBlur()
    }
  },
  watch: {
    value (val) {
      this.inputValue = val
    },
    inputValue (val, oldVal) {
      if (val === oldVal) return
      this.$emit('input', val)
    }
  },
  components: {
    'text-field': textField,
    'dropDown-menu': dropDownMenu
  }
}